<extend name='Index/index' />

<block name="main">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">管理员</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <table class="table table-striped b-t b-light">
                    <thead>
                        <tr>
                            <th  width="4%"><div align='center'>ID</div></th>
                            <th  width="8%"><div align='center'>用户名</div></th>
                            <th  width="10%"><div align='center'>所属组</div></th>
                            <th  width="12%"><div align='center'>最近登录时间</div></th>
                            <th  width="7%"><div align='center'>状态</div></th>
                            <th  width="12%"><div align='center'>创建时间</div></th>
                            <th  width="10%"><div align='center'>操作</div></th>
                        </tr>
                    </thead>
                    <tbody>
                        <foreach name="data" item="vo" key='k'>
                            <tr>
                                <td align='center'><{$vo.id}></td>
                                <td align='center'><{$vo.account}></td>
                                <td align='center'><{$vo.group_title}></td>
                                <td align='center'><{$vo.login_time|date="Y-m-d H:i:s",###}></td>
                                <td align='center'><a status="<{$vo['status']}>"><?php echo $vo['status']==0? 禁用: 激活?></a></td>
                                <td align='center'><{$vo.create_time|date="Y-m-d H:i:s",###}></td>
                                <td align='center'>
                                <if condition="in_array('Admin/admin_edit',$access)">
                                <a href="#"  class="disabled btn" >编辑</a>
                                <else/>
                                <a href="#"  data-toggle="modal" data-target="#myModal" class="btn btn-default">编辑</a>
                                </if>
                                <if condition="in_array('Admin/admin_del',$access)">
                                  <a href="" class="disabled btn">删除</a>
                                <else/>
                                  <a href=""  class="btn btn-default">删除</a>
                                </if>
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="result page"><{$page}></div>
        <p></p>
        <p></p>
    
    </div>

        <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">编辑管理员信息</h4>
                </div>
                <div class="modal-body">

                    <form class="form-horizontal" role="form" id="editform">
                        <div class="form-group">
                            <label for="inputAccount" class="col-sm-2 control-label">账号:</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" id="inputAccount">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户组:</label>
                            <div class="col-sm-9">
                                <select name="" id="selgroup" class="form-control">
                                    <volist name="list" id='vo'>
                                        <option value="<{$vo.id}>"><{$vo.title}></option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <span class="col-sm-2 control-label">账号状态:</span>
                            <div class="col-sm-offset-0 col-sm-8">
                                <div class="radio" id="radiostatus">
                                    <label>
                                        <input type="radio" name="status" value=1>允许登录
                                    </label>
                                    <label>
                                        <input type="radio" name="status" value=0>禁止登陆
                                    </label>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" id="hidden_id">
                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="modalclose">Close</button>
                    <button type="button" class="btn btn-primary" id="submit">Save changes</button>
                </div>
            </div>
        </div>
    </div>
<script>
    $('a:contains("编辑")').click(function(){
        var id = $(this).parents('tr').children('td').eq(0).html();
        var account = $(this).parents('tr').children('td').eq(1).html();
        var group = $(this).parents('tr').children('td').eq(2).html();
        var status = $(this).parents('tr').children('td').eq(4).children('a').attr("status");
        $('#hidden_id').val(id);
        $('#inputAccount').val(account);
        $('option:contains('+group+')').attr('selected','true');
        if (status=='1') {
            $(':radio').eq(0).attr('checked','true');
        }else{
            $(':radio').eq(1).attr('checked','true');
        }

        $('#submit').click(function(){
            var id = $('#hidden_id').val();
            var account = $('#inputAccount').val();
            var group_id = $('option:selected').val();
            var status = $(':radio:checked').val();
            $.ajax({
                url:"<{:U('Admin/admin_edit')}>",
                type:'post',
                data:{'id':id,'account':account,'group_id':group_id,'status':status},
                success:function(data){
                    alert(data);
                    window.location.reload();
                }
            })
        })
    })

    $("a:contains('删除')").click(function(){
            if (confirm('确认删除?')) {
                var id = $(this).parent().siblings().eq(0).html();
                var account = $(this).parent().siblings().eq(1).html();
                if (account == 'admin') {
                    alert('不允许删除管理员: admin');
                    return false;
                }
                var tr = $(this).parents('tr');
                $.ajax({
                    url: "<{:U('Admin/admin_del')}>",
                    data:{'id':id},
                    type: 'get',
                    success: function(data){
                        alert(data);
                        tr.remove();
                    }
                })
            }
        })

</script>
</block>